<include file="../Public/header" />
<link href="{:APPS_URL}/w3g/_static/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
  body{background-color: #f8f8f8;}
</style>
<div id="content">
    <div id="weiba" data-title="发新帖" class="panel" data-selected="true"  data-menu="msgmenu">
        <header>
            <div id="header-buttons">
                <a href="javascript:history.go(-1);">
                    <div id="back" class="header-menu-link" data-back="false">
                    </div>
                </a>
				<div class="header-menu-link" id="hmp-send">
                    <a class="sendBtn disable" onClick="doWeibaPost()" id="postbut" href="javascript:;">发布</a>
                </div>
            </div>
            <h1 class="hasback">
                发新帖
            </h1>
        </header>
      
      <div class="weibaPost">
      	<form method="post" action="{:U('w3g/Weiba/doPost')}" id="doWeibaPost">
        <php>if(empty($weiba_id)):</php>
          <div class="pure-form send_box">
            <select name="weiba_id" id="weiba_id" class="ts-select">
            <option value="0">请选择微吧</option>
            <volist name="weibacate" id="vo">
            <php>if(empty($vo['weibalist']))continue;</php>
            <optgroup label="{$vo.name}" disabled>{$vo.name}</optgroup>
                <volist name="vo.weibalist" id="wb">
                <option value="{$wb.weiba_id}">{$wb.weiba_name}</option>
                </volist>
            </volist>
            </select>
          </div>
        <php>else:</php>
          <input name="weiba_id" id="weiba_id" type="hidden" value="{$weiba_id}" />
        <php>endif;</php>
          <div class="pure-form send_box">
            <input type="text" id="title" name="title" class="ts-text" placeholder="输入帖子标题">
          </div>
          <div class="pure-form send_box">
          <textarea class="ts-textarea" name="content" id="post-content" rows="4" placeholder="输入帖子内容"></textarea>
          </div>
          <div class="ts-footer">
              <!-- 表情 --><a class="icon facelistbutton ts-listen" data-listen="weibo-facelist-show"><i class="fa-btn fa-btn-smile"></i></a>
              <!-- 图片 --><a class="icon imgbutton ts-listen" data-listen="weibo-upload-img" data-for="ts-upload-img-box" id="new-weibo-upload"><i class="fa-btn fa-btn-picture"></i></a>
          </div>
          <div id="ts-upload-img-box"></div>
        </form>
      </div>
    </div>
<include file="../Public/footer" />
<script type="text/javascript">
function doWeibaPost(){
	var weiba_id = $('#weiba_id').val();
	var title = $.trim($('#title').val());
	var content = $.trim($('#post-content').val());
	var imageIds = '';
	$('#ts-upload-img-box:first .file_list_view').each(function(i, el){
		imageIds = $(el).attr('data-id')+','+imageIds;
	});
	
	if(!weiba_id || weiba_id=='0'){
		$.ui.showMask("请选择微吧", true);
	}else if(!title){
		$('#title').focus();
	}else if(!content){
		$('#post-content').focus();
	}else{
		$.post(U('w3g/Weiba/doPost'), {
			weiba_id: weiba_id,
			title   : title,
			content : content,
			imageIds: imageIds
		}, function(data){
			if(data.status){
				$('#title').val('');
				$('#post-content').val('');
				$('#ts-upload-img-box').empty();
				$.ui.showMask('发布成功', true);
				window.location.href = U('w3g/Weiba/postDetail', ['post_id='+data.data]);
			}else{
				$.ui.showMask(typeof data=='string'?data:data.info,true);
			}
		}, 'json');
	}
}
</script>